<?php
include("../../share/config.php");

$sql = "select * from notice";
$sql1 = "select count(*) 'con' from notice";
$result=mysqli_query($conn,$sql);

//分页
$p_max=5;
if(isset($_GET['page'])&& $_GET['page'] != "false"){
	$now = $_GET['page'];
}
else{	
	$now = 1;
}
$result1=mysqli_query($conn,$sql1);
$total_data = mysqli_fetch_array($result1,MYSQLI_ASSOC);
$total_rows = $total_data["con"];
$count=0;
//分页
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
	if($now==1){
		$count = $count +1;
		if($count>5){
			break;
		}
	}
	else{
		$count = $count +1;
		if($count<=(5*($now-1))){
			continue;
		}
		if($count>(5*$now)){
			break;
		}
	}
	echo '<div class="panel panel-default">';
	echo '<div class="panel-heading">';
	echo ' <a class="panel-title" data-toggle="collapse" data-parent="#panel-573569" href="#panel-element-'.$row["id"].'">'.$row["title"].'</a>';
	echo '</div>';
	echo '<div id="panel-element-'.$row["id"].'" class="panel-collapse collapse">';
	echo '<div class="panel-body">';
	echo $row["con"];
	echo "</br>";
	echo '<a href="../../actions/admin/delete_post.php?postid='.$row["id"].'">删除此公告</a>';
	echo '</div>';
	echo '</div>';
	echo '</div>';
}
$howmany = ceil($total_rows/5);
echo '<ul class="pagination pagination-sm">';
if($now==1){
	echo '<li class="page-item disabled"><a href="#">Prev</a></li>';
}
else{
	$which = $now-1;
	echo '<li><a href="notice.php?page='.$which.'">Prev</a></li>';
}
for($i=1;$i<=$howmany;$i++){
	if($i==$now){
		echo '<li class="page-item disabled"><a href="notice.php?page='.$i.'">'.$i.'</a></li>';
	}
	else{
		echo '<li ><a href="notice.php?page='.$i.'">'.$i.'</a></li>';
	}
}

if($now==$i-1){
	echo '<li class="page-item disabled"><a href="#">Next</a></li></ul>';
}
else{
	$which = $now+1;
	echo '<li><a href="notice.php?page='.$which.'">Next</a></li></ul>';
}
?>
 